const Model = require('../model');
const { buyItem } = Model;

const buyItemController = {
  all(req, res) {
    buyItem.find({})
      .exec((err, manfacturers) => res.json(manfacturers))
  },
  byUserId(req, res) {
    const idParams = req.params.UserId;
    console.log(idParams);
    buyItem
      .find({ id: idParams })
      .exec((err, buyItem) => res.json(buyItem));
  },
  submit(req, res) {
    const requestBody = req.body;
    const newbuyItem = new buyItem(requestBody);

    newbuyItem.save();
    console.log("收到新的订单！");
    console.log(newbuyItem);
    
    res.json(newbuyItem);
  },
  remove(req, res) {
    const idParams = req.params.id;

    buyItem.find({ _id: idParams }).remove( (err, removed) => res.json(idParams) )
  }
}

module.exports = buyItemController;